import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import resources.JogoServerHandler;

public class JogoServer {

	private static final int TCP_PORTA = 9123;

	private static final int TAMANHO_BUFFER = 2048;

	public static void main(String[] args) throws IOException {

		IoAcceptor acceptor = new NioSocketAcceptor();

		acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		acceptor.getFilterChain().addLast(
				"codec",
				new ProtocolCodecFilter(new TextLineCodecFactory(Charset
						.forName("UTF-8"))));

		acceptor.setHandler(new JogoServerHandler());
		acceptor.getSessionConfig().setReadBufferSize(TAMANHO_BUFFER);

		acceptor.bind(new InetSocketAddress(TCP_PORTA));

		if (JogoServerHandler.DEBUG_ENABLED) {
			System.out.println("Servidor do Jogo Cara a Cara iniciado!");
			System.out.println("Aguardando conexoes...");
		}
	}
}
